package com.ruoyi.controller.achievements;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.service.achievements.AcvDepManageService;
import com.ruoyi.service.achievements.AcvTpService;
import com.ruoyi.util.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * @author zeo
 * @explain 绩效模板管理
 * @date 2020/8/22 8:55
 */
@Controller
@RequestMapping("/acvTpManage")
public class AcvTpManageController extends BaseController {

    @Autowired
    AcvTpService acvTpService;

    @Autowired
    AcvDepManageService acvDepManageService;

    private String prefix = "achievements/tp";

    @GetMapping()
    public String acvTpManage(ModelMap mmap) {
        mmap.put("secondaryDeptList", acvDepManageService.findSecondaryDept());
        return prefix + "/tp";
    }

    @RequestMapping("/findTwoDept")
    @ResponseBody
    public TableDataInfo findDeptJob(@RequestParam Map map) {
        return getDataTable(acvTpService.findTwoDept(map));
    }

    @RequestMapping("/findThreeDept")
    @ResponseBody
    public TableDataInfo findThreeDept(@RequestParam Map map) {
        return getDataTable(acvTpService.findThreeDept(map));
    }

    @RequestMapping("/findJobByDeptId")
    @ResponseBody
    public TableDataInfo findJobByDeptId(@RequestParam Map map) {
        return getDataTable(acvTpService.findJobByDeptId(map));
    }

    /**
     * 上传说有岗位的附件
     *
     * @param file
     * @return
     * @throws Exception
     */
    @RequestMapping("/importTemplateFile")
    @ResponseBody
    public AjaxResult importTemplateFile(MultipartFile file) throws Exception {
        return acvTpService.importTemplateFile(file);
    }

    /**
     * 上传单个岗位的附件
     *
     * @param file
     * @param jobId
     * @return
     * @throws Exception
     */
    @RequestMapping("/uploadTemplateData")
    @ResponseBody
    public AjaxResult uploadTemplateData(MultipartFile file, String jobId) throws Exception {
        return toAjax(acvTpService.uploadTemplateData(file, jobId));
    }

    @RequestMapping("/downloadTemplateByJobId")
    @ResponseBody
    public AjaxResult downloadTemplateByJobId(String jobId) {
        return acvTpService.downloadTemplateByJobId(jobId);
    }

    @RequestMapping("/findTemplateDataByJobId")
    @ResponseBody
    public TableDataInfo findTemplateDataByJobId(String jobId) {
        return getDataTable(acvTpService.findTemplateDataByJobId(jobId));
    }

}
